<template>
  <div class="venue-list-container">
    <!-- 动态背景 -->
    <div class="bg-animation">
      <div class="bg-circle circle-1"></div>
      <div class="bg-circle circle-2"></div>
    </div>
    
    <div class="page-header">
      <div class="header-content">
        <div class="header-text">
          <h2 class="page-title">
            <span class="title-icon">🏟️</span>
            场馆管理中心
          </h2>
          <p class="subtitle">智能场馆管理 · 数据驱动决策</p>
        </div>
        <el-button type="primary" @click="handleCreate">
          <el-icon><Plus /></el-icon>
          <span>新增场馆</span>
        </el-button>
      </div>
    </div>
    
    <!-- 搜索区域 -->
    <div class="search-card-tech">
      <div class="card-glow"></div>
      <div class="card-border"></div>
      <div class="search-header">
        <h3 class="section-title">
          <span class="title-icon">🔍</span>
          智能筛选
        </h3>
      </div>
      
      <el-form :model="searchForm" class="tech-form">
        <div class="search-grid">
          <div class="form-item-tech">
            <label class="tech-label">场馆名称</label>
            <el-input 
              v-model="searchForm.name" 
              placeholder="请输入场馆名称" 
              clearable 
              class="tech-input"
            />
          </div>
          
          <div class="form-item-tech">
            <label class="tech-label">场馆类型</label>
            <el-select 
              v-model="searchForm.type" 
              placeholder="请选择场馆类型" 
              clearable 
              class="tech-select"
            >
              <el-option label="全部" value="" />
              <el-option v-for="item in venueTypes" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
          
          <div class="form-item-tech">
            <label class="tech-label">状态</label>
            <el-select 
              v-model="searchForm.status" 
              placeholder="请选择状态" 
              clearable 
              class="tech-select"
            >
              <el-option label="全部" value="" />
              <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
          
          <div class="form-actions">
            <el-button type="primary" @click="handleSearch">
              <el-icon><Search /></el-icon>
              <span>搜索</span>
            </el-button>
            <el-button @click="resetSearch">
              <el-icon><Refresh /></el-icon>
              <span>重置</span>
            </el-button>
          </div>
        </div>
      </el-form>
    </div>
    
    <!-- 表格区域 -->
    <div class="table-card-tech">
      <div class="card-glow"></div>
      <div class="card-border"></div>
      
      <div class="table-header">
        <h3 class="section-title">
          <span class="title-icon">📊</span>
          场馆数据概览
          <span class="title-badge">{{ total }}</span>
        </h3>
        <div class="table-stats">
          <span class="stat-item">
            <span class="stat-label">总计</span>
            <span class="stat-value">{{ total }}</span>
          </span>
        </div>
      </div>
      
      <div class="table-container" style="overflow-x: auto;">
        <el-table 
          :data="venueList" 
          style="min-width: 1800px;" 
          v-loading="loading" 
          class="tech-table"
          :header-cell-style="{ background: '#f8f9fa', color: '#495057', fontWeight: '600' }"
        >
          <el-table-column prop="id" label="ID" width="80">
            <template #default="scope">
              <span class="id-badge">{{ scope.row.id }}</span>
            </template>
          </el-table-column>
          
          <el-table-column prop="name" label="场馆名称" width="180">
            <template #default="scope">
              <div class="venue-info">
                <span class="venue-name">{{ scope.row.name }}</span>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column prop="type" label="场馆类型" width="120">
            <template #default="scope">
              <el-tag class="tech-tag type-tag" effect="dark">
                {{ getVenueTypeText(scope.row.type) }}
              </el-tag>
            </template>
          </el-table-column>
          
          <el-table-column prop="location" label="位置" width="300">
            <template #default="scope">
              <div class="location-info">
                <el-icon class="location-icon"><MapPin /></el-icon>
                <span>{{ scope.row.location }}</span>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column prop="open_time" label="开放时间" width="180">
            <template #default="scope">
              <div class="time-info">
                <el-icon class="time-icon"><Clock /></el-icon>
                <span>{{ scope.row.open_time }}</span>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column prop="status" label="状态" width="100">
            <template #default="scope">
              <el-tag 
                :type="scope.row.status == 1 || scope.row.status == '1' ? 'success' : 'info'"
                class="tech-tag status-tag"
                effect="dark"
              >
                {{ scope.row.status == 1 || scope.row.status == '1' ? '启用' : '禁用' }}
              </el-tag>
            </template>
          </el-table-column>
          
          <el-table-column label="操作" width="500">
            <template #default="scope">
              <div class="action-buttons">
                <el-button class="tech-action-btn edit-btn" size="small" @click="handleEdit(scope.row)">
                  <el-icon><Edit /></el-icon>
                  <span>编辑</span>
                </el-button>
                <el-button class="tech-action-btn manage-btn" size="small" @click="handleTimeSlots(scope.row)">
                  <el-icon><Setting /></el-icon>
                  <span>时间段</span>
                </el-button>
                <el-button class="tech-action-btn info-btn" size="small" @click="handleBookingStatus(scope.row)">
                  <el-icon><Plus /></el-icon>
                  <span>创建活动</span>
                </el-button>
                <el-button class="tech-action-btn stats-btn" size="small" @click="handleBookingStatistics(scope.row)">
                  <el-icon><DataAnalysis /></el-icon>
                  <span>统计</span>
                </el-button>
                <el-button class="tech-action-btn delete-btn" size="small" @click="handleDelete(scope.row)">
                  <el-icon><Delete /></el-icon>
                  <span>删除</span>
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      
      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          class="tech-pagination"
        />
      </div>
    </div>

    <!-- 新增/编辑场馆弹窗 -->
    <el-dialog 
      v-model="dialogVisible" 
      :title="isEdit ? '编辑场馆' : '新增场馆'" 
      width="1200px"
      :close-on-click-modal="false"
      @closed="handleDialogClosed"
    >
      <el-form 
        ref="formRef" 
        :model="form" 
        :rules="rules" 
        label-width="120px"
        v-loading="formLoading"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="场馆名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入场馆名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场馆类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择场馆类型" style="width: 100%">
                <el-option v-for="item in venueTypes" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入详细地址" @change="searchAddress" />
              <el-button type="primary" size="small" style="margin-top: 5px;" @click="searchAddress">定位地址</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在区域" prop="location">
              <el-input v-model="form.location" placeholder="请输入所在区域" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开放时间" prop="openTime">
              <el-time-picker
                v-model="openTimeRange"
                is-range
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                format="HH:mm"
                value-format="HH:mm"
                style="width: 100%"
                @change="handleTimeChange"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 地图容器 -->
        <el-form-item label="地图位置">
          <div id="map-container" style="height: 300px; width: 100%; border: 1px solid #ddd;"></div>
          <div style="margin-top: 10px;">
            <span>经度: {{ form.longitude || '未设置' }}</span>
            <span style="margin-left: 20px;">纬度: {{ form.latitude || '未设置' }}</span>
          </div>
        </el-form-item>
        
        <el-form-item label="场馆介绍" prop="description">
          <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请输入场馆介绍" />
        </el-form-item>

        <el-form-item label="场馆图片" prop="images">
          <el-upload
            action="https://dpcurdgwzmkg.sealosbja.site/api/v1/admin/upload"
            list-type="picture-card"
            :file-list="fileList"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            :on-success="handleUploadSuccess"
            :on-error="handleUploadError"
            :headers="uploadHeaders"
            :limit="10"
            accept="image/png,image/jpg,image/jpeg,image/gif,image/webp"
            multiple
          >
            <el-icon><Plus /></el-icon>
            <template #tip>
              <div class="el-upload__tip">
                支持jpg/png/gif/webp格式，单张图片不超过2MB，最多上传10张
              </div>
            </template>
          </el-upload>
          <el-dialog v-model="previewVisible" title="图片预览">
            <img style="width: 100%" :src="getFullImageUrl(previewImageUrl)" alt="预览图片" />
          </el-dialog>
        </el-form-item>
        
        <el-form-item label="场馆状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitForm" :loading="submitting">确定</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- venueList 为空时提示 -->
    <div v-if="!loading && venueList.length === 0" style="text-align:center;color:#999;margin:20px 0;">暂无数据</div>
  </div>
</template>

<script>
import { ref, reactive, computed, onMounted, watch, onBeforeUnmount, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Search, Refresh, Edit, Setting, View as ViewIcon, Delete, LocationInformation as MapPin, Clock, DataAnalysis } from '@element-plus/icons-vue'
import request from '@/utils/request'

export default {
  name: 'VenueList',
  components: {
    Plus,
    Search,
    Refresh,
    Edit,
    Setting,
    ViewIcon,
    Delete,
    MapPin,
    Clock,
    DataAnalysis
  },
  setup() {
    const route = useRoute()
    const router = useRouter()
    const loading = ref(false)
    const formLoading = ref(false)
    const submitting = ref(false)
    const venueList = ref([])
    const total = ref(0)
    const currentPage = ref(1)
    const pageSize = ref(10)
    const dialogVisible = ref(false)
    const formRef = ref(null)
    
    // 百度地图相关
    let map = null
    let marker = null
    let geolocation = null
    
    // 图片上传相关
    const fileList = ref([])
    const previewVisible = ref(false)
    const previewImageUrl = ref('')
    
    // 开放时间范围
    const openTimeRange = ref([])
    
    // 场馆类型选项
    const venueTypes = [
      { label: '篮球场', value: 'basketball' },
      { label: '足球场', value: 'football' },
      { label: '网球场', value: 'tennis' },
      { label: '羽毛球馆', value: 'badminton' },
      { label: '游泳馆', value: 'swimming' },
      { label: '乒乓球室', value: 'pingpong' }
    ]
    
    // 状态选项（全部用字符串）
    const statusOptions = [
      { label: '启用', value: '1' },
      { label: '禁用', value: '0' }
    ]
    
    // 搜索表单
    const searchForm = reactive({
      name: '',
      type: '',
      status: ''
    })
    
    // 表单数据
    const form = reactive({
      id: null,
      name: '',
      type: 'basketball',
      address: '',
      location: '',
      contactPhone: '',
      openTime: '',
      latitude: null,
      longitude: null,
      description: '',
      images: [],
      status: 1
    })
    
    // 判断是否为编辑模式
    const isEdit = computed(() => !!form.id)
    
    // 上传请求头
    const uploadHeaders = computed(() => {
      return {
        Authorization: `Bearer ${localStorage.getItem('admin_token')}`
      }
    })
    
    // 表单验证规则
    const rules = {
      name: [{ required: true, message: '请输入场馆名称', trigger: 'blur' }],
      type: [{ required: true, message: '请选择场馆类型', trigger: 'change' }],
      address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
      location: [{ required: true, message: '请输入所在区域', trigger: 'blur' }]
    }
    
    // 初始化百度地图
    const initMap = () => {
      nextTick(() => {
        if (!window.BMap) {
          console.warn('百度地图API未加载')
          return
        }
        
        const mapContainer = document.getElementById('map-container')
        if (!mapContainer) return
        
        // 创建地图实例
        map = new window.BMap.Map('map-container')
        
        // 设置中心点和缩放级别
        const point = new window.BMap.Point(116.404, 39.915) // 北京天安门
        map.centerAndZoom(point, 11)
        map.enableScrollWheelZoom(true)
        
        // 添加控件
        map.addControl(new window.BMap.NavigationControl())
        map.addControl(new window.BMap.ScaleControl())
        
        // 点击地图设置标记点和经纬度
        map.addEventListener('click', (e) => {
          map.clearOverlays()
          const newPoint = new window.BMap.Point(e.point.lng, e.point.lat)
          marker = new window.BMap.Marker(newPoint)
          map.addOverlay(marker)
          
          // 更新表单经纬度
          form.longitude = e.point.lng
          form.latitude = e.point.lat
          
          // 反向地理编码获取地址
          const geoc = new window.BMap.Geocoder()
          geoc.getLocation(newPoint, (rs) => {
            if (rs) {
              const addComp = rs.addressComponents
              form.address = `${addComp.province}${addComp.city}${addComp.district}${addComp.street}${addComp.streetNumber}`
              form.location = addComp.district
            }
          })
        })
        
        // 如果有经纬度，定位到该位置
        if (form.latitude && form.longitude) {
          const venuePoint = new window.BMap.Point(form.longitude, form.latitude)
          map.centerAndZoom(venuePoint, 15)
          marker = new window.BMap.Marker(venuePoint)
          map.addOverlay(marker)
        }
      })
    }
    
    // 根据地址搜索位置
    const searchAddress = () => {
      if (!form.address || !map) return
      
      const localSearch = new window.BMap.LocalSearch(map, {
        renderOptions: { map: map, autoViewport: true }
      })
      
      localSearch.setSearchCompleteCallback((results) => {
        if (results && results.getPoi(0)) {
          const poi = results.getPoi(0)
          map.centerAndZoom(poi.point, 15)
          map.clearOverlays()
          marker = new window.BMap.Marker(poi.point)
          map.addOverlay(marker)
          
          // 更新经纬度
          form.longitude = poi.point.lng
          form.latitude = poi.point.lat
          
          // 获取区域
          const geoc = new window.BMap.Geocoder()
          geoc.getLocation(poi.point, (rs) => {
            if (rs) {
              const addComp = rs.addressComponents
              form.location = addComp.district
            }
          })
        } else {
          ElMessage.warning('未找到该地址，请尝试更详细的地址')
        }
      })
      
      localSearch.search(form.address)
    }
    
    // 处理时间变更
    const handleTimeChange = (val) => {
      if (val && val.length === 2) {
        form.openTime = `${val[0]}-${val[1]}`
      } else {
        form.openTime = ''
      }
    }
    
    // 图片预览
    const handlePictureCardPreview = (file) => {
      previewImageUrl.value = file.url
      previewVisible.value = true
    }
    
    // 图片移除
    const handleRemove = (file) => {
      const index = fileList.value.findIndex(item => item.uid === file.uid)
      if (index !== -1) {
        fileList.value.splice(index, 1)
        form.images = form.images.filter(img => img !== file.url)
      }
    }
    
    // 从完整URL中提取相对路径
    const extractRelativePath = (url) => {
      if (!url) return ''
      
      // 如果是相对路径，直接返回
      if (!url.startsWith('http')) {
        return url
      }
      
      // 从完整URL中提取相对路径
      const urlObj = new URL(url)
      return urlObj.pathname
    }

    // 图片上传成功
    const handleUploadSuccess = (response, file) => {
      if (response.code === 200) {
        // 后端返回的是相对路径，如 /uploads/venue/xxx.jpg
        const relativePath = response.data.url
        
        // 构建完整的图片URL用于显示
        const fullUrl = getFullImageUrl(relativePath)
        
        // 添加到文件列表（显示用完整URL）
        fileList.value.push({
          name: file.name,
          url: fullUrl,
          uid: file.uid
        })
        
        // 添加到表单数据（保存用相对路径）
        form.images.push(relativePath)
        
        ElMessage.success('图片上传成功')
      } else {
        ElMessage.error(response.message || '图片上传失败')
      }
    }
    
    // 图片上传失败
    const handleUploadError = (error, file) => {
      console.error('图片上传失败:', error)
      ElMessage.error('图片上传失败，请重试')
    }
    
    // 弹窗关闭处理
    const handleDialogClosed = () => {
      // 清理地图
      if (map) {
        map = null
        marker = null
      }
    }
    
    // 监听路由变化
    watch(() => route.path, (newPath) => {
      if (newPath === '/venue/create') {
        // 如果是新增页面，自动打开弹窗
        handleCreate()
        // 跳转回列表页面但保持弹窗打开
        router.replace('/venue/list')
      }
    }, { immediate: true })
    
    // 获取场馆列表
    const fetchVenueList = async () => {
      loading.value = true
      try {
        const params = {
          page: currentPage.value,
          perPage: pageSize.value,
          keyword: searchForm.name || undefined,
          type: searchForm.type ? String(searchForm.type) : undefined,
          status: searchForm.status !== '' ? String(searchForm.status) : undefined
        }
        
        const token = localStorage.getItem('admin_token')
        const response = await request.get('/v1/admin/venues', {
          params
        })
        
        if (response && response.code === 200) {
          const { data } = response
          venueList.value = data.venues || []
          total.value = data.total || 0
        } else {
          ElMessage.error(response?.message || '获取场馆列表失败')
        }
      } catch (error) {
        console.error('获取场馆列表失败', error)
        ElMessage.error('获取场馆列表失败: ' + (error.response?.data?.message || error.message))
      } finally {
        loading.value = false
      }
    }
    
    // 搜索
    const handleSearch = () => {
      currentPage.value = 1
      fetchVenueList()
    }
    
    // 重置搜索
    const resetSearch = () => {
      Object.keys(searchForm).forEach(key => {
        searchForm[key] = ''
      })
      handleSearch()
    }
    
    // 页码变化
    const handleCurrentChange = (page) => {
      currentPage.value = page
      fetchVenueList()
    }
    
    // 每页条数变化
    const handleSizeChange = (size) => {
      pageSize.value = size
      fetchVenueList()
    }
    
    // 新增场馆
    const handleCreate = () => {
      resetForm()
      fileList.value = []
      openTimeRange.value = []
      dialogVisible.value = true
      nextTick(() => {
        initMap()
      })
    }
    
    // 编辑场馆
    const handleEdit = (row) => {
      resetForm()
      form.id = row.id
      form.name = row.name
      form.type = row.type
      form.address = row.address
      form.location = row.location
      form.contactPhone = row.contact_phone || ''
      form.openTime = row.open_time || ''
      form.latitude = row.latitude
      form.longitude = row.longitude
      form.description = row.description || ''
      form.status = row.status
      form.images = row.images || []
      
      // 设置开放时间范围
      if (form.openTime) {
        const [start, end] = form.openTime.split('-')
        openTimeRange.value = [start, end]
      } else {
        openTimeRange.value = []
      }
      
      // 设置图片列表
      fileList.value = form.images.map((url, index) => {
        // 使用修复后的getFullImageUrl函数处理URL
        const fullUrl = getFullImageUrl(url)
        return {
          name: `图片${index + 1}`,
          url: fullUrl,
          uid: Date.now() + index
        }
      })
      
      dialogVisible.value = true
      nextTick(() => {
        initMap()
      })
    }
    
    // 提交表单
    const submitForm = () => {
      formRef.value.validate(async (valid) => {
        if (!valid) return
        
        submitting.value = true
        try {
          // 确保图片数据为相对路径
          const cleanImages = form.images.map(img => extractRelativePath(img))
          
          const submitData = {
            name: form.name,
            type: form.type,
            address: form.address,
            location: form.location,
            contactPhone: form.contactPhone,
            openTime: form.openTime,
            latitude: form.latitude,
            longitude: form.longitude,
            description: form.description,
            images: cleanImages,
            status: form.status
          }
          
          let response
          if (isEdit.value) {
            response = await request.put(`/v1/admin/venues/${form.id}`, submitData)
          } else {
            response = await request.post('/v1/admin/venues', submitData)
          }
          
          if (response && response.code === 200) {
            ElMessage.success(isEdit.value ? '更新成功' : '创建成功')
            dialogVisible.value = false
            fetchVenueList()
          } else {
            ElMessage.error(response?.message || '操作失败')
          }
        } catch (error) {
          console.error('提交失败', error)
          ElMessage.error('操作失败: ' + (error.response?.data?.message || error.message))
        } finally {
          submitting.value = false
        }
      })
    }
    
    // 删除场馆
    const handleDelete = (row) => {
      ElMessageBox.confirm(`确认删除场馆 "${row.name}" 吗？`, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          await request.delete(`/v1/admin/venues/${row.id}`)
          ElMessage.success('删除成功')
          fetchVenueList()
        } catch (error) {
          console.error('删除场馆失败', error)
          ElMessage.error('删除场馆失败: ' + (error.response?.data?.message || error.message))
        }
      }).catch(() => {})
    }
    
    // 获取场馆类型文本
    const getVenueTypeText = (type) => {
      const found = venueTypes.find(item => item.value === type)
      return found ? found.label : type
    }
    
    // 重置表单
    const resetForm = () => {
      form.id = null
      form.name = ''
      form.type = 'basketball'
      form.address = ''
      form.location = ''
      form.contactPhone = ''
      form.openTime = ''
      form.latitude = null
      form.longitude = null
      form.description = ''
      form.images = []
      form.status = 1
      
      // 重置其他数据
      fileList.value = []
      openTimeRange.value = []
      previewVisible.value = false
      previewImageUrl.value = ''
      
      if (formRef.value) {
        formRef.value.clearValidate()
      }
    }
    
    // 处理时间槽
    const handleTimeSlots = (row) => {
      router.push(`/venue/time-slots/${row.id}`)
    }
    
    // 处理预订统计
    const handleBookingStatistics = (row) => {
      router.push(`/venue/booking-statistics/${row.id}`)
    }
    
    // 处理预订情况 - 跳转到预订创建页面
    const handleBookingStatus = (row) => {
      // 明确传递意图：为指定场馆创建活动
      router.push({ name: 'VenueBooking', params: { id: row.id }, query: { createForVenue: 'true' } })
    }
    
    function getFullImageUrl(url) {
      if (!url) return '';
      
      const correctBaseUrl = 'https://dpcurdgwzmkg.sealosbja.site';
      const wrongBaseUrl = 'https://hm.yunxitech.cn';
      
      // 如果URL包含错误的域名，强制替换成正确的域名
      if (url.startsWith(wrongBaseUrl)) {
        return url.replace(wrongBaseUrl, correctBaseUrl);
      }
      
      // 如果已经是正确的完整http/https链接，直接返回
      if (url.startsWith('http')) {
        return url;
      }
      
      // 如果是相对路径，拼接正确的域名
      if (url.startsWith('/uploads/')) {
        return correctBaseUrl + url;
      }
      
      // 默认情况：拼接域名和uploads/venue/路径
      return `${correctBaseUrl}/uploads/venue/${url.replace(/^uploads[\/\\]venue[\/\\]/, '')}`;
    }
    
    onMounted(() => {
      fetchVenueList()
    })
    
    return {
      loading,
      formLoading,
      submitting,
      venueList,
      venueTypes,
      statusOptions,
      searchForm,
      currentPage,
      pageSize,
      total,
      dialogVisible,
      formRef,
      form,
      isEdit,
      rules,
      fileList,
      previewVisible,
      previewImageUrl,
      openTimeRange,
      uploadHeaders,
      handleSearch,
      resetSearch,
      handleCurrentChange,
      handleSizeChange,
      handleCreate,
      handleEdit,
      submitForm,
      handleDelete,
      getVenueTypeText,
      initMap,
      searchAddress,
      handleTimeChange,
      handlePictureCardPreview,
      handleRemove,
      handleUploadSuccess,
      handleUploadError,
      handleDialogClosed,
      handleTimeSlots,
      handleBookingStatistics,
      handleBookingStatus,
      getFullImageUrl,
      extractRelativePath
    }
  }
}
</script>

<style lang="scss" scoped>

/* 修复交互问题 */
.venue-list-container .form-actions {
  position: relative !important;
  z-index: 100 !important;
}

.venue-list-container .form-actions .el-button {
  position: relative !important;
  z-index: 101 !important;
  pointer-events: auto !important;
  cursor: pointer !important;
}

.venue-list-container .table-container {
  overflow-x: auto !important;
  position: relative !important;
  z-index: 50 !important;
}

.venue-list-container .table-container::-webkit-scrollbar {
  height: 8px !important;
  background-color: rgba(0, 0, 0, 0.1) !important;
  border-radius: 4px !important;
}

.venue-list-container .table-container::-webkit-scrollbar-thumb {
  background-color: rgba(102, 126, 234, 0.6) !important;
  border-radius: 4px !important;
  cursor: pointer !important;
}

.venue-list-container .table-container::-webkit-scrollbar-thumb:hover {
  background-color: rgba(102, 126, 234, 0.8) !important;
}

.venue-list-container .action-buttons .el-button {
  position: relative !important;
  z-index: 102 !important;
  pointer-events: auto !important;
}

.venue-list-container .bg-animation {
  pointer-events: none !important;
  z-index: -100 !important;
}

// 全局变量
:root {
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --warning-gradient: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  --dark-bg: #0f0f23;
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-primary: #2c3e50;
  --text-secondary: #6c757d;
  --glow-color: rgba(102, 126, 234, 0.3);
  --border-color: rgba(0, 0, 0, 0.1);
}

/* 修复交互问题 */
.form-actions {
  position: relative !important;
  z-index: 100 !important;
  
  .el-button {
    position: relative !important;
    z-index: 101 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
  }
}

.table-container {
  overflow-x: auto !important;
  position: relative !important;
  z-index: 50 !important;
  
  &::-webkit-scrollbar {
    height: 8px !important;
    background-color: rgba(0, 0, 0, 0.1) !important;
    border-radius: 4px !important;
  }
  
  &::-webkit-scrollbar-thumb {
    background-color: rgba(102, 126, 234, 0.6) !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    
    &:hover {
      background-color: rgba(102, 126, 234, 0.8) !important;
    }
  }
}

.action-buttons .el-button {
  position: relative !important;
  z-index: 102 !important;
  pointer-events: auto !important;
}

.bg-animation {
  pointer-events: none !important;
  z-index: -100 !important;
  
  .bg-circle {
    pointer-events: none !important;
  }
}

.venue-list-container {
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 50%, #f1f3f4 100%);
  position: relative;
  overflow: hidden;
}

// 动态背景动画
.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none !important;
  z-index: -100 !important;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(102, 126, 234, 0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;

  &.circle-1 {
    width: 250px;
    height: 250px;
    top: 20%;
    left: 80%;
    animation-delay: 0s;
  }

  &.circle-2 {
    width: 180px;
    height: 180px;
    bottom: 30%;
    left: 20%;
    animation-delay: 3s;
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  33% { transform: translateY(-20px) rotate(5deg); }
  66% { transform: translateY(-10px) rotate(-5deg); }
}

// 头部区域 - 白色主题
.page-header {
  margin-bottom: 40px;
  position: relative;
  z-index: 1;
  padding: 24px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid #e9ecef;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.header-text {
  .page-title {
    color: #1a1a1a;
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 12px;

    .title-icon {
      font-size: 32px;
    }
  }

  .subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    margin: 0;
    font-weight: 300;
  }
}

// 搜索卡片 - 白色主题
.search-card-tech {
  background: #ffffff;
  border: 1px solid #e9ecef;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

  &:hover {
    border-color: #dee2e6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}

.card-glow {
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: var(--primary-gradient);
  border-radius: 16px;
  opacity: 0;
  z-index: -1;
  transition: opacity 0.3s ease;
  filter: blur(8px);
}

.card-border {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 16px;
  background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.search-header {
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;

  .title-icon {
    font-size: 20px;
  }
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  align-items: end;
}

.form-item-tech {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tech-label {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-start;
  position: relative;
  z-index: 10;
  
  .el-button {
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
  }
}

// 按钮样式
.tech-button-primary {
  background: var(--primary-gradient);
  border: none;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 6px;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
  }

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
    
    &::before {
      left: 100%;
    }
  }
}

.tech-button-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 6px;

  &:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
  }
}

// 表格卡片
.table-card-tech {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  position: relative;
  overflow: hidden;
  z-index: 1;

  &:hover {
    border-color: #667eea;
    
    .card-glow {
      opacity: 0.3;
    }
  }
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;

  .title-badge {
    font-size: 12px;
    background: var(--primary-gradient);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
  }
}

.table-stats {
  display: flex;
  gap: 20px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;

  .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
  }

  .stat-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
  }
}

// 表格样式
.table-container {
  overflow-x: auto !important;
  position: relative !important;
  z-index: 50 !important;
  
  &::-webkit-scrollbar {
    height: 8px !important;
    background-color: rgba(0, 0, 0, 0.1) !important;
    border-radius: 4px !important;
  }
  
  &::-webkit-scrollbar-thumb {
    background-color: rgba(102, 126, 234, 0.6) !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    
    &:hover {
      background-color: rgba(102, 126, 234, 0.8) !important;
    }
  }

  :deep(.tech-table) {
    background: transparent;
    
    .el-table__header {
      background: transparent;
      
      th {
        background: var(--primary-gradient) !important;
        color: white !important;
        border: none;
        font-weight: 600;
      }
    }
    
    .el-table__body {
      tr {
        background: transparent;
        border: none;
        transition: all 0.3s ease;
        
        &:hover {
          background: rgba(102, 126, 234, 0.1) !important;
          transform: scale(1.01);
        }
        
        td {
          border: none;
          border-bottom: 1px solid var(--border-color);
          color: var(--text-primary);
        }
      }
    }
  }
}

.id-badge {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: #00f2fe;
  padding: 2px 6px;
  background: rgba(0, 242, 254, 0.1);
  border-radius: 4px;
  border: 1px solid rgba(0, 242, 254, 0.3);
}

.venue-info {
  .venue-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
  }
}

.location-info,
.time-info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;

  .location-icon,
  .time-icon {
    color: #667eea;
  }
}

.tech-tag {
  font-weight: 500;
  border-radius: 12px;
  border: none;
  
  &.type-tag {
    background: rgba(67, 233, 123, 0.2);
    color: #43e97b;
  }
  
  &.status-tag {
    &.el-tag--success {
      background: rgba(0, 242, 254, 0.2);
      color: #00f2fe;
    }
    
    &.el-tag--info {
      background: rgba(255, 255, 255, 0.1);
      color: var(--text-secondary);
    }
  }
}

// 操作按钮
.action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tech-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  border: none;

  &.edit-btn {
    background: rgba(102, 126, 234, 0.2);
    color: #667eea;
    
    &:hover {
      background: rgba(102, 126, 234, 0.3);
      transform: translateY(-1px);
    }
  }

  &.manage-btn {
    background: rgba(67, 233, 123, 0.2);
    color: #43e97b;
    
    &:hover {
      background: rgba(67, 233, 123, 0.3);
      transform: translateY(-1px);
    }
  }

  &.info-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    transition: all 0.3s ease;
  }

  &.info-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  }

  &.stats-btn {
    background: rgba(0, 242, 254, 0.2);
    color: #00f2fe;
    
    &:hover {
      background: rgba(0, 242, 254, 0.3);
      transform: translateY(-1px);
    }
  }

  &.delete-btn {
    background: rgba(245, 108, 108, 0.2);
    color: #f56c6c;
    
    &:hover {
      background: rgba(245, 108, 108, 0.3);
      transform: translateY(-1px);
    }
  }
}

// 分页
.pagination-container {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  
  :deep(.tech-pagination) {
    .el-pagination__total {
      color: var(--text-secondary);
    }
    
    .el-pager li {
      background: rgba(255, 255, 255, 0.05);
      color: var(--text-secondary);
      border: 1px solid var(--border-color);
      margin: 0 2px;
      
      &:hover {
        background: rgba(102, 126, 234, 0.2);
        color: var(--text-primary);
      }
      
      &.is-active {
        background: var(--primary-gradient);
        color: white;
        border-color: #667eea;
      }
    }
    
    .btn-prev,
    .btn-next {
      background: rgba(255, 255, 255, 0.05);
      color: var(--text-secondary);
      border: 1px solid var(--border-color);
      
      &:hover {
        background: rgba(102, 126, 234, 0.2);
        color: var(--text-primary);
      }
    }
  }
}

.dialog-footer {
  text-align: right;
}

// 表单输入框样式覆盖
:deep(.tech-input .el-input__wrapper) {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  
  &:hover {
    border-color: #667eea;
  }
  
  &.is-focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
  }
  
  .el-input__inner {
    color: var(--text-primary);
    
    &::placeholder {
      color: var(--text-secondary);
    }
  }
}

:deep(.tech-select .el-select__wrapper) {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  
  &:hover {
    border-color: #667eea;
  }
  
  &.is-focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
  }
  
  .el-select__placeholder {
    color: var(--text-secondary);
  }
}
</style> 